# coding: UTF-8
# ----------
# Project_Name : pythonProject
# File_Name : huangcongbing
# Author : asus
# Date_Time:2022/4/22 10:52
# Description :
# ----------
from selenium import  webdriver
import time
from selenium.webdriver.common.by import By
def foo1():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get(r"D:\pyworkspace\T79\pythonProject\selenium3\example.html")
    #1.alert弹出框
    driver.find_element(By.NAME,'alterbutton').click()
    time.sleep(1)
    #切换到弹出框，并获取弹出框对象,警告弹出框
    alert = driver.switch_to.alert

    #点击确定
    alert.accept()   #accept:确定
    time.sleep(2)

    #2.confirm弹出框，确认弹出框
    driver.find_element(By.NAME,'confirmbutton').click()
    time.sleep(1)
    confirm = driver.switch_to.alert
    #点击取消
    confirm.dismiss()
    time.sleep(1)
    #点击确定
    confirm.accept()
    time.sleep(1)

    #3.prompt弹出框
    driver.find_element(By.NAME,'promptbutton').click()
    time.sleep(1)
    #切换到弹出框，并获取但出框对象
    prompt = driver.switch_to.alert
    #输入框输入
    prompt.send_keys('汇智动力')
    time.sleep(2)
    #点击确定
    prompt.accept()
    time.sleep(2)

    driver.quit()


if __name__ == "__main__":
    foo1()